package com.example.shop_2211.utils

import android.content.Context
import android.widget.ImageView
import androidx.databinding.BindingAdapter
import com.bumptech.glide.Glide
import com.youth.banner.Banner
import com.youth.banner.loader.ImageLoader

object ImageLoad {

    //封装biandingAdpter实现图片加载 //url为可空对象，防止跳转到指定页面时，路径不存在，导致报错问题
    @JvmStatic
    @BindingAdapter("img_url")
    fun loadImage(imageView: ImageView,url:String?){
        if(url!=null){
            Glide.with(imageView.context).load(url).into(imageView)
        }

    }
    @JvmStatic
    @BindingAdapter("banner_url")
    fun loadBanner(banner: Banner,list:List<String>?){
        if (list != null) {
           banner.setImages(list)
               .setImageLoader(object :ImageLoader(){
                   override fun displayImage(context: Context?, path: Any?, imageView: ImageView?) {
                       Glide.with(context!!).load(path).into(imageView!!)
                   }
               })
               .start()
        }
    }
}